﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Golf.WebUI.AdminShow.Ajax
{
    public partial class SystemManagement : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                switch (Request.Form["action"])
                {
                    case "ManagementDel":
                        ManagementDel();
                        break;
                    case "AdminGroupsAdd":
                        AdminGroupsAdd();
                        break;
                    case "AdminGroupsDel":
                        AdminGroupsDel();
                        break;
                }
            }
        }
        /// <summary>
        /// 添加管理员组
        /// </summary>
        private void AdminGroupsAdd()
        {
            string GroupName = Server.UrlDecode(Request.Form["txtGroupName"]);
            string GroupIntro = Server.UrlDecode(Request.Form["txtGroupIntro"]);
            string PowerIdList = Server.UrlDecode(Request.Form["txtPowerIdList"]);
            DateTime AddTime = DateTime.Parse(Server.UrlDecode(Request.Form["txtAddTime"]));
            Golf.Model.Golf_AdminGroups model = new Golf.Model.Golf_AdminGroups();
            model.GroupName = GroupName;
            model.GroupIntro = GroupIntro;
            model.PowerIdList = PowerIdList;
            model.AddTime = AddTime;

            Golf.BLL.Golf_AdminGroups bll = new Golf.BLL.Golf_AdminGroups();
            if (bll.Add(model) > 0)
            {
                Response.Write("0");//添加成功
            }
            else
            {
                Response.Write("1");//添加失败
            }
        }
        /// <summary>
        /// 删除管理员组
        /// </summary>
        private void AdminGroupsDel()
        {
            Golf.BLL.Golf_AdminGroups bll = new Golf.BLL.Golf_AdminGroups();
            if (Request.Form["id"] != null && Request.Form["id"].Trim() != "")
            {
                int Id = (Convert.ToInt32(Server.UrlDecode(Request.Form["id"])));
                if (bll.Delete(Id))
                {
                    Response.Write("0");//删除成功
                }
                else
                {

                    Response.Write("1");//删除失败
                }
            }
        }
        /// <summary>
        /// 删除管理员
        /// </summary>
        public void ManagementDel()
        {
            Golf.BLL.Golf_Admin bll = new Golf.BLL.Golf_Admin();
            if (Request.Form["id"] != null && Request.Form["id"].Trim() != "")
            {
                int Id = (Convert.ToInt32(Server.UrlDecode(Request.Form["id"])));
                if (bll.Delete(Id))
                {
                    Response.Write("0");//删除成功
                }
                else
                {

                    Response.Write("1");//删除失败
                }
            }
        }
    }
}
